package com.iwhalecloud.bss.kite.cucc.service.session;

import com.iwhalecloud.bss.kite.cart.common.util.KiteSessionUtil;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.session.ICuccSessionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.inf.req.NoticeExitReqDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.inf.rsp.NoticeExitRspDTO;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.CuccSessionIdCache;
import com.ztesoft.common.logger.api.ZLogger;
import com.ztesoft.common.logger.factory.ZLoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class CuccSessionService implements ICuccSessionService {

    private final ZLogger logger = ZLoggerFactory.getLogger(CuccSessionService.class, KeyConsts.LOG_MODULE);

    @Override
    public NoticeExitRspDTO expirySessionInfo(NoticeExitReqDTO noticeExitReqDTO) {
        logger.info("运营平台退出登录================");
        NoticeExitRspDTO noticeExitRspDTO = new NoticeExitRspDTO();
        String authSessionId = noticeExitReqDTO.getAuthsessionid();
        String loginInfoJson = CuccSessionIdCache.get(authSessionId);
        if (!KiteStringUtils.isEmpty(loginInfoJson)) {
            String kiteSessionId = CuccSessionIdCache.get("s" + authSessionId);
            KiteSessionUtil.clearLoginInfo(kiteSessionId);
            CuccSessionIdCache.delete(authSessionId);
            CuccSessionIdCache.delete("s" + authSessionId);
            noticeExitRspDTO.setResultCode("1");
            logger.info("退出登录处理完成================");
        }
        else {
            noticeExitRspDTO.setResultCode("2");
            noticeExitRspDTO.setResultMsg(authSessionId + ",在本系统不存在");
        }
        return noticeExitRspDTO;
    }
}
